#include <p30F4011.h>
#include <libpic30.h>

void write_eeprom(_prog_addressT location, int value);
int read_eeprom(_prog_addressT location);
int ee_get_checksum(void);
void ee_set_checksum(int newval);
int ee_get_use_devices(void);
void ee_set_use_devices(int newval);
int ee_get_throttle_min(void);
void ee_set_throttle_min(int newval);
int ee_get_throttle_max(void);
void ee_set_throttle_max(int newval);
int ee_get_precharge_time(void);
void ee_set_precharge_time(int newval);
int ee_get_rotor_time_const(void);
void ee_set_rotor_time_const(int newval);
int ee_get_motor_poles(void);
void ee_set_motor_poles(int newval);
int ee_get_encoder_count(void);
void ee_set_encoder_count(int newval);
int ee_get_current_gain(void);
void ee_set_current_gain(int newval);
int ee_get_current_bias(void);
void ee_set_current_bias(int newval);
int ee_get_voltage_gain(void);
void ee_set_voltage_gain(int newval);
int ee_get_max_volt(void);
void ee_set_max_volt(int newval);
int ee_get_min_volt(void);
void ee_set_min_volt(int newval);
int ee_get_motor_volt(void);
void ee_set_motor_volt(int newval);
int ee_get_motor_hertz(void);
void ee_set_motor_hertz(int newval);
int ee_get_max_amps(void);
void ee_set_max_amps(int newval);
int ee_get_overheat_ctrl(void);
void ee_set_overheat_ctrl(int newval);
int ee_get_overheat_motor(void);
void ee_set_overheat_motor(int newval);
int ee_get_last_faults(void);
void ee_set_last_faults(int newval);
int ee_get_canbus_speed(void);
void ee_set_canbus_speed(int newval);
long ee_get_canbus_id(void);
void ee_set_canbus_id(long newval);
unsigned int ee_calcChecksum(void);
void ee_save_checksum(void);
int ee_verify_checksum(void);

//values for EEPROM_USE_DEVICES
#define EE_USE_MAIN_CONTACTOR		1
#define EE_USE_MAIN_CONTACTOR_SENSE	2
#define EE_USE_PRECHARGE			4
#define EE_USE_ENCODER				8
#define EE_USE_POT_THROTTLE			16
#define EE_USE_HEPA_THROTTLE		32
#define EE_USE_CANBUS_THROTTLE		64
#define EE_USE_MOTOR_TEMP			128
#define EE_USE_CTRL_TEMP			256

//LAST FAULT defines are actually in globals.h

//CANBUS speed defines
#define EE_CANBUS_SPEED_1M		0
#define EE_CANBUS_SPEED_500K	1
#define EE_CANBUS_SPEED_250K	3
#define EE_CANBUS_SPEED_125K	7
#define EE_CANBUS_SPEED_625K	15 //actually 62.5
